﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/Admin/_AdminLayout.cshtml";
}

@using PagedList
@using PagedList.Mvc
<div style="background: #fff; text-align: right; height: 60px; width: 100%; font-size: 12px; border: 1px solid #ccc;">
    <span style="font-size: 18px; font-weight: bold; float: left; padding-top: 17px; padding-left: 15px;">
        <img src="../../Content/Images/Admin/product.png" />
        QUẢN LÍ KHÁCH HÀNG
    </span>
</div>
@Html.Raw(ViewBag.ThongBao)
<br />
<br />
<table cellspacing="0" rules="rows" class="rows" border="1" style="width: 100%; border-collapse: collapse;">
    <tr class="item_title" style="color: White; background-color: #CCCCCC; font-family: Tahoma; font-size: 12px; font-weight: bold; height: 30px;">
        <th>ID</th>
        <th>Tên khách hàng</th>
        <th>Email</th>
        <th>Địa chỉ</th>
        <th>Số điện thoại</th>
        <th>Tên đăng nhập</th>
        <th>Loại khách hàng</th>
        <th>Trạng thái</th>
        <th></th>
        <th></th>
    </tr>
    @{PagedList<BabyToys.Models.KhachHang> khachhangs = ViewBag.onePageOfKhachHang;}
    @foreach (var khachhang in khachhangs)
    {
        <tr class="item_row" style="border-color: #F0F0F0; border-style: Solid; height: 40px;">
            <td class="item_float">@khachhang.IdKhachHang</td>
            <td class="item_float">@khachhang.TenDayDu</td>
            <td class="item_float">@khachhang.Email</td>
            <td class="item_float">@khachhang.DiaChi</td>
            <td class="item_float">@khachhang.SoDienThoai</td>
            <td class="item_float">@khachhang.TenDangNhap</td>
            <td class="item_float">@khachhang.LoaiKhachHang.TenLoai</td>
            <td class="item_float">
                <select id="@Html.Raw("IsActive" + khachhang.IdKhachHang)" onchange="CapNhatTrangThai(@khachhang.IdKhachHang)">
                        <option value="True" @Html.Raw((khachhang.IsActive == true) ? "selected=\"selected\"" : "")>Active</option>
                        <option value="False" @Html.Raw((khachhang.IsActive == false) ? "selected=\"selected\"" : "")>Locked</option>
                </select>
                 <script>
                     function CapNhatTrangThai(id) {
                         var x = confirm("Bạn có chắc muốn cập nhật user này?");
                         if (x == true) {
                             var ten = '#IsActive' + id;
                             var id = id;
                             var trangthai = $(ten).val();
                             $.post("/AdminKhachHang/CapNhatTrangThai/", { "id": id, "trangthai": trangthai },
                                 function (data) {
                                     alert("Cập Nhật Thành Công");
                                 });
                         }
                         else {
                             window.location.reload();
                         }
                     }
                    </script>
            </td>
            <td class="item_float"></td>
            <td class="item_float">
                <div class="hidden-phone visible-desktop action-buttons">
                    <a href="~/AdminKhachHang/SuaKhachHang/@khachhang.IdKhachHang" class="btnXoa small blue button btnSua">Sửa</a>
                </div>
            </td>
        </tr>
    }
</table>
@Html.PagedListPager((IPagedList)ViewBag.OnePageOfKhachHang,page=>Url.Action("Index",new{page}),PagedListRenderOptions.OnlyShowFivePagesAtATime)